<template>
	<view>
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="用户名" name="">
				<uni-easyinput  v-model="user.username"   placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="密码" name="">
				<uni-easyinput type="password"   v-model="user.password" placeholder="请输入密码" />
			</uni-forms-item>
			<uni-forms-item label="学院" name="">
				<uni-combox @change="departmentChange" :candidates="user.departments" placeholder="请选择学院"
					v-model="user.department"></uni-combox>
			</uni-forms-item>
			<uni-forms-item label="专业" name="">
				<uni-combox @change="majorChange" :candidates="user.majors" placeholder="请选择专业"
					v-model="user.major"></uni-combox>
			</uni-forms-item>
			<uni-forms-item label="电话" name="">
				<uni-easyinput @change="telephoneChange" v-model="user.telephone" placeholder="请输入电话" />
			</uni-forms-item>
			<uni-forms-item label="邮箱" name="">
				<uni-easyinput @change="emailChange" v-model="user.email" placeholder="请输入邮箱" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="register">注册</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					username: '',
					password: '',
					departments: ['信息工程'],
					department: '',
					majors: ["移动应用"],
					major: '',
					telephone: '',
					email: '',
				}
			}
		},
		methods: {
			departmentChange(e) {
				this.user.department = e.detail.value
			},
			departmentcollege(e) {
				this.user.departmentcollege = e.detail.value
			},
			telephoneChange(e) {
				this.user.telephone = e.detail.value
			},
			emailChange(e) {
				this.user.email = e.detail.value
			},
			register(e) {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/register',
					method: 'POST',
					data: this.user,
					success: res => {
						if (res.data.success) {
							uni.showToast({
								title: '注册成功',
								duration: 30000
							});
						} else {
							uni.showToast({
								title: '注册失败',
								icon: 'none'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});

				uni.showToast({
					title: '' + this.user.username + '\r' + this.user.college + '\t' +
						this.user.specializ + '\t' + this.user.telephone + '\t' +
						this.user.email + '\t',
					icon: 'none'
				});
			},
			onLoad: () => {
				uni.onTabBarMidButtonTap(function(e) {
					console.log(e)
				})
			}

		}
	}
</script>

<style>

</style>